'''
Created on 30.05.2011

@author: blaze
'''

from t2g.model.trac.comment import CommentEntry, TicketComments

class TicketEntry(object):
    '''
    classdocs
    '''
    
    def __init__(self, id, type, time, severity, priority, owner, reporter, version,
                 milestone, status, resolution, summary, description, keywords):
        
        self.id = id
        self.type = type
        self.time = time
        self.severity = severity
        self.priority = priority
        self.owner = owner
        self.reporter = reporter
        self.version = version
        self.milestone = milestone
        self.status = status
        self.resolution = resolution
        self.summary = summary
        self.description = description
        self.keywords = keywords
        
        self.comments = TicketComments(self.id)
    
    def addComment(self, comment):
        self.comments.addComment(comment)

    def addComments(self, comments):
        for comment in comments.getComments():
            self.comments.addComment(comment)
    
    def __str__(self):
        return self.summary + "[" + str(self.id) + "@" + self.reporter + "]"
        
    def __lt__(self, other):
        return self.id < other.id
    def __gt__(self, other):
        return self.id > other.id
    def __eq__(self, other):
        return self.id == other.id
    def __le__(self, other):
        return self.id <= other.id
    def __ge__(self, other):
        return self.id >= other.id
    def __ne__(self, other):
        return self.id != other.id

class TicketManager(object):
    
    #TODO:
    # - add user mapping
    def __init__(self):
        self.tickets = []
         
    def addTicket(self, ticket):        
        self.tickets.append(ticket)
    
    def getTickets(self):
        return self.tickets
    
    def __len__(self):
        return len(self.tickets)
    
    def printStat(self):
        print("Total tickets: %i" % len(self.tickets))